<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div>
      <input type="text" v-model="num" placeholder="请输入1-100之间的整数" />
      <input type="button" value="猜一猜" @click="f()" />
      <h1>{{ result }}</h1>
    </div>

    <!-- 本地引入vue.js框架文件 -->
    <script src="js/vue.js"></script>
    <script>
      let x = parseInt(Math.random() * 100 + 1);
      let flag = 0;
      let app = new Vue({
        el: "body>div",
        data: {
          result: "",
          num: "",
        },
        methods: {
          f() {
            flag++;
            if (app.num > x) {
              app.result = "第" + flag + "次，猜大了";
            }
            if (app.num < x) {
              app.result = "第" + flag + "次，猜小了";
            }
            if (app.num == x) {
              app.result = "猜对了,用了" + flag + "次";
            }
          },
        },
      });
    </script>
  </body>
</html>
